package com.guide.dao.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import com.guide.bizdto.IndexSel;
import com.guide.dao.TravelorgDao;
import com.guide.domain.Guide;
import com.guide.domain.Travelorg;
import com.guide.domain.TravelorgQuery;
import com.guide.persistence.TravelorgMapper;
@Repository("travelorgDao")
public class TravelorgDaoImpl implements TravelorgDao{

	@Autowired
	private TravelorgMapper travelorgMapper;
	
	@Override
	public long insertTravelorg(Travelorg travelorg) {
		// TODO Auto-generated method stub
		return travelorgMapper.insert(travelorg);
	}

	@Override
	public Travelorg getTravelorgByUserId(Long userId) {
		TravelorgQuery query = new TravelorgQuery();
		query.createCriteria().andUserIdEqualTo(userId);
		List<Travelorg> travelorgs = travelorgMapper.selectByExampleWithBLOBs(query);
		if(!CollectionUtils.isEmpty(travelorgs)) {
			return travelorgs.get(0);
		}
		return null;
	}

	@Override
	public void updateByPrimaryKeySelective(Travelorg travelorg) {
		// TODO Auto-generated method stub
		travelorgMapper.updateByPrimaryKeySelective(travelorg);
	}

	@Override
	public Travelorg getTravelorgById(Long id) {
		// TODO Auto-generated method stub
		return travelorgMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Travelorg> getTravelorgListByIndex(IndexSel indexSel) {
		// TODO Auto-generated method stub
		String city=null;
		if(!StringUtils.isEmpty(indexSel.getCity())){
			city = indexSel.getCity();
		}
		return travelorgMapper.selectByExampleWithBLOBsForIndex(city, indexSel.getPageIndex()*indexSel.getPageSize(), indexSel.getPageSize());
	}

	@Override
	public int countTravelorgListByIndex(IndexSel indexSel) {
		// TODO Auto-generated method stub
		String city=null;
		if(!StringUtils.isEmpty(indexSel.getCity())){
			city = indexSel.getCity();
		}
		return travelorgMapper.counttByExampleWithBLOBsForIndex(city);
	}

	@Override
	public Travelorg getTravelorgBylicnumAndbuslicnum(String licnum,
			String buslicnum) {
		// TODO Auto-generated method stub
		TravelorgQuery query = new TravelorgQuery();
		query.createCriteria().andLicnumEqualTo(licnum).andBuslicnumEqualTo(buslicnum);
		List<Travelorg> travelorgList = travelorgMapper.selectByExample(query);
		if(!CollectionUtils.isEmpty(travelorgList)) {
			return travelorgList.get(0);
		}
		return null;
	}
	
	

	
}
